<?
/**
 * Class u 
 *
 * @author  novebeta
 * @license http://www.opensource.org/licenses/bsd-license.php
 * @since   version 1.0.0
 * @package Libraries
 */
namespace Libraries;
class u {
    public static function isAjaxRequest() {
        return isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] === 'XMLHttpRequest';
    }    
    public static function get_user_id($session) {
        return $session->getValue('user_id');
    }
    public static function format_status($var) {
        return $var == 1 ? "Aktif" : "Non Aktif";
    }
    function generatePassword($length = 8) {
        $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
        $count = mb_strlen($chars);
        for ($i = 0, $result = ''; $i < $length; $i++) {
            $index = rand(0, $count - 1);
            $result.=mb_substr($chars, $index, 1);
        }
        return $result;
    }
    function random_string($length, $include_number = false) {
        $original_string = $include_number ? array_merge(range(0, 9), range('a', 'z'),
                        range('A', 'Z')) : array_merge(
                        range('a', 'z'), range('A', 'Z'));
        $original_string = implode("", $original_string);
        return substr(str_shuffle($original_string), 0, $length);
    }
    public static function get_number($number) {
        return str_replace(",", "", $number);
    }
    public static function getMenuTree($username) {
        $data = "[{text: 'Aplikasi',
                  expanded: false,
                  children:[
                    {
                    text: 'Master',
                    expanded: false,
                    children:[{
                            text: 'Proyek',
                            id: 'jun.ProyekGrid',
                            leaf: true
                        },
                        {
                            text: 'Kavling',
                            id: 'jun.KavlingGrid',
                            leaf: true
                        },
                        {
                            text: 'Bank',
                            id: 'jun.BankGrid',
                            leaf: true
                        },
                        ]
                    },
                    {
                    text: 'Transaksi',
                    expanded: false,
                    children:[
                        {
                            text: 'Kas Masuk',
                            id: 'jun.KasMasukGrid',
                            leaf: true
                        },
                        {
                            text: 'Transaksi Bahan',
                            id: 'jun.TransaksiBahanGrid',
                            leaf: true
                        },
                        ]
                    },
                    {
                    text: 'Laporan',
                    expanded: false,
                    children:[
                        {
                            text: 'Pengeluaran per Kavling',
                            id: 'jun.PengeluaranPerKavling',
                            leaf: true
                        },
                        {
                            text: 'Pengeluaran per Proyek',
                            id: 'jun.PengeluaranPerProyek',
                            leaf:true
                        },                
                        {
                            text: 'Pemasukan per Kavling',
                            id: 'jun.MtBankTransGrid',
                            leaf: true
                        },
                        {
                            text: 'Pemasukan per Proyek',
                            id: 'jun.MtGlTransReportGrid',
                            leaf:true
                        },
                        ]
                    },
                    ]
                  },

       {
                text: 'Ganti Password',
                id: 'jun.PasswordWin',
                leaf: true
              },
            {
                text: 'Logout ($username)',
                id: 'logout',
                leaf: true
              }]";
        return $data;
    }
}
?>